/*     */ package com.hs.activation.controller;
/*     */ 
/*     */ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/*     */ import com.hs.activation.common.result.BaseController;
/*     */ import com.hs.activation.common.result.Result;
/*     */ import com.hs.activation.dto.ActivationDTO;
/*     */ import com.hs.activation.entity.Activation;
/*     */ import com.hs.activation.service.IActivationLogService;
/*     */ import com.hs.activation.service.IActivationService;
/*     */ import com.hs.activation.vo.ActivationVO;
/*     */ import com.hs.activation.vo.AlertActionExpirationTimeVO;
/*     */ import io.swagger.annotations.Api;
/*     */ import io.swagger.annotations.ApiOperation;
/*     */ import io.swagger.annotations.ApiParam;
/*     */ import java.lang.reflect.Field;
/*     */ import java.lang.reflect.Method;
/*     */ import java.text.ParseException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.web.bind.annotation.DeleteMapping;
/*     */ import org.springframework.web.bind.annotation.GetMapping;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.PostMapping;
/*     */ import org.springframework.web.bind.annotation.PutMapping;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.RestController;
/*     */ 
/*     */ @RestController
/*     */ @RequestMapping({"/activation"})
/*     */ @Api(value = "激活信息接口", tags = {"激活信息接口"})
/*     */ public class ActivationController
/*     */   extends BaseController
/*     */ {
/*     */   @ApiOperation(value = "获取激活信息", notes = "获取激活信息", httpMethod = "GET")
/*     */   @GetMapping({""})
/*     */   public Result list(@ApiParam("查询条件") String key, @ApiParam("数据状态") Integer state) {
/*  44 */     List<ActivationDTO> result = this.activationService.listDTO(key, state);
/*  45 */     List<Object> data = new ArrayList();
/*  46 */     result.forEach(t -> {
/*     */           int RemainingDate = daysBetween(new Date(), t.getExpirationTime());
/*     */           Map<String, Object> entity = toMap(t);
/*     */           entity.put("RemainingDate", Integer.valueOf(RemainingDate));
/*     */           data.add(entity);
/*     */         });
/*  52 */     return ok(data);
/*     */   }
/*     */   @Autowired
/*     */   IActivationService activationService; @Autowired
/*     */   IActivationLogService activationLogService;
/*     */   @ApiOperation(value = "获取激活信息", notes = "获取激活信息-分页", httpMethod = "GET")
/*     */   @GetMapping({"/{current}/{size}"})
/*     */   public Result list(@PathVariable @ApiParam(value = "当前页", required = true) Long current, @PathVariable @ApiParam(value = "每页个数", required = true) Long size, @ApiParam("查询条件") String key, @ApiParam("数据状态") Integer state) {
/*  60 */     Page<Activation> page = new Page(current.longValue(), size.longValue());
/*  61 */     return ok(this.activationService.pageDTO(page, key, state));
/*     */   }
/*     */ 
/*     */   
/*     */   @ApiOperation(value = "获取激活信息", notes = "根据ID获取激活信息", httpMethod = "GET")
/*     */   @GetMapping({"/{id}"})
/*     */   public Result findById(@PathVariable @ApiParam(value = "当前页", required = true) Integer id) {
/*  68 */     return ok(this.activationService.getById(id));
/*     */   }
/*     */ 
/*     */   
/*     */   @DeleteMapping({"/{id}"})
/*     */   @ApiOperation(value = "删除激活信息", notes = "根据id删除激活信息", httpMethod = "DELETE")
/*     */   public Result deleteById(@PathVariable @ApiParam("ID") Integer id) {
/*  75 */     this.activationLogService.removeByActivationId(id);
/*  76 */     return ok(Boolean.valueOf(this.activationService.removeById(id)));
/*     */   }
/*     */ 
/*     */   
/*     */   @PostMapping({""})
/*     */   @ApiOperation(value = "保存激活信息", notes = "新增一条保存信息", httpMethod = "POST")
/*     */   public Result save(@RequestBody ActivationVO activationVO) {
/*  83 */     if (this.activationService.save(activationVO)) {
/*  84 */       return ok();
/*     */     }
/*  86 */     return fail();
/*     */   }
/*     */ 
/*     */   
/*     */   @PutMapping({""})
/*     */   @ApiOperation(value = "保存激活信息", notes = "更新保存信息", httpMethod = "PUT")
/*     */   public Result update(@RequestBody ActivationVO activationVO) {
/*  93 */     if (this.activationService.update(activationVO)) {
/*  94 */       return ok();
/*     */     }
/*  96 */     return fail();
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @GetMapping({"group"})
/*     */   @ApiOperation(value = "获取分组信息List", httpMethod = "GET")
/*     */   public Result groupList() {
/* 105 */     return ok(this.activationService.getGroupList());
/*     */   }
/*     */ 
/*     */   
/*     */   @PutMapping({"/state/{id}/{state}"})
/*     */   @ApiOperation(value = "更改激活信息的状态 0:未启用，1：启用", httpMethod = "PUT")
/*     */   public Result activationState(@PathVariable @ApiParam("ID") Integer id, @PathVariable @ApiParam("状态") Integer state) {
/* 112 */     if (this.activationService.setState(id, state)) {
/* 113 */       return ok();
/*     */     }
/* 115 */     return fail();
/*     */   }
/*     */ 
/*     */   
/*     */   @PutMapping({"expiration_time"})
/*     */   @ApiOperation("修改激活时间")
/*     */   public Result expirationTime(@RequestBody AlertActionExpirationTimeVO expirationTimeVO) {
/* 122 */     return ok(this.activationService.updateExpirationTime(expirationTimeVO));
/*     */   }
/*     */   public static Map<String, Object> toMap(Object obj) {
/* 125 */     Map<String, Object> map = new HashMap<>();
/* 126 */     Class<?> classType = obj.getClass();
/* 127 */     Field[] fields = classType.getDeclaredFields();
/*     */     
/* 129 */     for (Field field : fields) {
/*     */       try {
/* 131 */         String fieldName = getFieldName(field);
/* 132 */         String firstLetter = fieldName.substring(0, 1).toUpperCase();
/* 133 */         String methodHead = "get";
/* 134 */         Class<?> ftype = field.getType();
/* 135 */         if (ftype.getName().equals("boolean")) {
/* 136 */           methodHead = "is";
/*     */         }
/*     */         
/* 139 */         String getMethodName = methodHead + methodHead + firstLetter;
/*     */         
/* 141 */         Method getMethod = classType.getMethod(getMethodName, new Class[0]);
/*     */         
/* 143 */         Object value = getMethod.invoke(obj, new Object[0]);
/* 144 */         map.put(fieldName, value);
/* 145 */       } catch (Exception ee) {
/* 146 */         ee.printStackTrace();
/*     */       } 
/*     */     } 
/* 149 */     return map;
/*     */   }
/*     */   public static String getFieldName(Field field) {
/* 152 */     return field.getName().replace("_", "");
/*     */   }
/*     */   
/*     */   public static int daysBetween(Date smdate, Date bdate) {
/* 156 */     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/*     */     try {
/* 158 */       smdate = sdf.parse(sdf.format(smdate));
/* 159 */     } catch (ParseException e) {
/* 160 */       e.printStackTrace();
/*     */     } 
/*     */     try {
/* 163 */       bdate = sdf.parse(sdf.format(bdate));
/* 164 */     } catch (ParseException e) {
/* 165 */       e.printStackTrace();
/*     */     } 
/* 167 */     Calendar cal = Calendar.getInstance();
/* 168 */     cal.setTime(smdate);
/* 169 */     long time1 = cal.getTimeInMillis();
/* 170 */     cal.setTime(bdate);
/* 171 */     long time2 = cal.getTimeInMillis();
/* 172 */     long between_days = (time2 - time1) / 86400000L;
/*     */     
/* 174 */     return Integer.parseInt(String.valueOf(between_days));
/*     */   }
/*     */ }


/* Location:              C:\Users\yzc\Desktop\新建文件夹 (3)\activation-0.0.16.jar!\BOOT-INF\classes\com\hs\activation\controller\ActivationController.class
 * Java compiler version: 16 (60.0)
 * JD-Core Version:       1.1.3
 */